﻿using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
///Base 的摘要说明
/// </summary>
public class Base : CnGine.Web.PageBase
{

    public int PageIndex = 1;
    public int PageSize = 20;

    public Base()
    {
        this.Init += new EventHandler(Base_Init);
    }

    void Base_Init(object sender, EventArgs e)
    {
        PageIndex = base.QueryInt32("page");
        if (PageIndex < 1) PageIndex = 1;
        ValidateSession();


    }

    public virtual void ValidateSession()
    {

    }


    public string GetBImagae(object o)
    {
        string s = o.ToString();
        s = System.Text.RegularExpressions.Regex.Replace(s, "/(\\d*)/", "/$1/Big/");
        return GetImage(s);
    }
    public string GetSImagae(object o)
    {
        string s = o.ToString();
        s = System.Text.RegularExpressions.Regex.Replace(s, "/(\\d*)/", "/$1/Small/");
        return GetImage(s);
    }
    public string DateBefore(object o)
    {
        string dateDiff = "";
        DateTime DateTimeOld = new DateTime();
        if (o != null) DateTime.TryParse(o.ToString(), out DateTimeOld);
        DateTime DateTimeNew = System.DateTime.Now;

        TimeSpan ts1 = new TimeSpan(DateTimeOld.Ticks);
        TimeSpan ts2 = new TimeSpan(DateTimeNew.Ticks);
        TimeSpan ts = ts1.Subtract(ts2).Duration();
        int day = ts.Days;
        int hou = ts.Hours;
        int minu = ts.Minutes;
        int sec = ts.Seconds;
        if (day > 0)
        {
            if (day > 30)
            {
                if (day > 364)
                {
                    dateDiff += day / 365 + "年";
                }
                else
                {
                    dateDiff += day / 30 + "个月";
                }
            }
            else
            {
                dateDiff += day.ToString() + "天";
            }
        }
        else
        {
            if (hou > 0)
            {
                dateDiff += hou.ToString() + "小时";
            }
            else
            {
                if (minu > 0)
                {
                    dateDiff += minu.ToString() + "分钟";
                }
                else
                {
                    if (sec > 0)
                    {
                        dateDiff += sec.ToString() + "秒";
                    }
                    else
                    {
                        dateDiff += "0秒";
                    }
                }
            }
        }
        if (DateTimeNew.CompareTo(DateTimeOld) > 0)
        {
            dateDiff += "前";
        }
        else
        {
            dateDiff += "后";
        }
        return dateDiff;
    }

    public string GetFunnyComment(int lou)
    {

        if (lou == 1)
        {
            return "这位小朋友成功到达火星表面成为外星人，我们要向他看齐！";
        }
        else
            return string.Format("这位小朋友蹲在海底{0}米处游来游去", lou * 10);
    }
    public string GetFunnyComment2(int lou)
    {

        if (lou == 1)
        {
            return "这位小朋友爬上地球陆地成为了无知又愚蠢的人类";
        }
        else
            return string.Format("这位小朋友蹲在河底{0}米处游来游去", lou * 10);
    }

}